package com.niu1078.joe.utils.dimen;

import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.niu1078.joe.app.Joe;

public final class DimenUtil {
    /**
     * 获取屏幕的宽
     * @return 宽
     */
    public static int getScreenWidth() {
        final Resources resources = Joe.getApplicationContext().getResources();
        final DisplayMetrics dm = resources.getDisplayMetrics();
        return dm.widthPixels;
    }

    /**
     * 获取屏幕的高
     * @return 高
     */
    public static int getScreenHeight() {
        final Resources resources = Joe.getApplicationContext().getResources();
        final DisplayMetrics dm = resources.getDisplayMetrics();
        return dm.heightPixels;
    }

    public static int dp2px(float dp) {
        float density = Joe.getApplicationContext() .getResources().getDisplayMetrics().density;    // 获取屏幕密度
        int px = (int) (dp * density + 0.5);    // 加0.5是为了四舍五入
        return px;
    }


}
